/** Navigation */


jQuery(function( $ ){
    /**
     * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
     * @see http://flesler.demos.com/jquery/scrollTo/
     * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
     */
    
    // The default axis is 'y', but in this demo, I want to scroll both
    // You can modify any default like this
    $.localScroll.defaults.axis = 'yx';
    
    // Scroll initially if there's a hash (#something) in the url 
    $.localScroll.hash({
        target: '#content', // Could be a selector or a jQuery object too.
        queue:true,
        duration:1500
    });
    
    /**
     * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
     * also affect the >> and << links. I want every link in the page to scroll.
     */
    $.localScroll({
        target: '#content', // could be a selector or a jQuery object too.
        queue:true,
        duration:1500,
        hash:true,
        easing: 'easeInOutExpo',
        onBefore:function( e, anchor, $target ){
            // The 'this' is the settings object, can be modified
        },
        onAfter:function( anchor, settings ){
          var hash = window.location.hash;
          hash = hash.split('#');
          hash = "."+hash[1];
          $(hash).addClass('aktiv')
            // The 'this' contains the scrolled element (#content)
        }
    });
});


$(window).load(function() {
	mCustomScrollbars();
});

function mCustomScrollbars(){
	/* 
	malihu custom scrollbar function parameters: 
	1) scroll type (values: "vertical" or "horizontal")
	2) scroll easing amount (0 for no easing) 
	3) scroll easing type 
	4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
	5) scrollbar height/width adjustment (values: "auto" or "fixed")
	6) mouse-wheel support (values: "yes" or "no")
	7) scrolling via buttons support (values: "yes" or "no")
	8) buttons scrolling speed (values: 1-20, 1 being the slowest)
	*/
	$("#mcs_container").mCustomScrollbar("vertical",300,"easeOutCirc",1.05,"auto","yes","yes",15); 
}

/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}




// handle nav selection
function deselectNav() {
    $(this)
        .parents('ul:first')
            .find('li')
                .removeClass('aktiv')
            .end()
        .end()
}


function deselectNav2() {
    $(this)
        .parents('ul:first')
            .find('li')
                .removeClass('aktiv')
            .end()
        .end();
        var hash = window.location.hash;
        hash = hash.split('#');
        hash = "."+hash[1];
        // alert(hash);
        $(hash)
          .addClass('aktiv')
}

function selectNav(){
  var hash = window.location.hash;
  hash = hash.split('#');
  hash = "."+hash[1];
  // alert(hash);
  $(hash)
    .addClass('aktiv');
  $(hash)
    .parents('li').addClass('aktiv');
  // var lipunkt = $(hash).nextAll('li').prev().addClass('aktiv');
  // console.log(lipunkt);
  // $(hash).nextAll('li').prev('li').addClass('aktiv');
}





/* GOOGLE */
function initialize() {
    var latlng = new google.maps.LatLng(52.8485,8.04);
    var myOptions = {
      zoom: 16,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  	var contentString = '<div class="infowindow-content">' +
  	      '<h2 style="line-height:1.2em">Direkt an der Soeste. Die erste Adresse für Zahnmedizin und Zahnästhetik. – In und um Cloppenburg:</h2>'+
  	      '<img src="img/logo.png" width="179" height="31" style="margin-top:4px" alt="Logo">'+
          '<h1>Dr. Ambrus - Zahnärzte an der Soeste</h1>'+
  				'<p>Mühlenstraße 24</p>'+
  		    '<p>49661 Cloppenburg</p>'+
  				'<br><span class="label">Telefon</span>04471/850 55 0<br>'+
  				'<br><a href="http://maps.google.de/maps?hl=de&amp;q=dr+ambrus&amp;ie=UTF8&amp;ll=52.847153,8.043006&amp;spn=0.004633,0.010536&amp;z=14&amp;iwloc=A&amp;cid=13188837281456039753&amp;source=embed onclick="window.close(); openWindow(this.href); return false">Routenplaner</a>'+				
  				'</div>';


  		var infowindow = new google.maps.InfoWindow({
  		    content: contentString
  		});

  		var image = 'img/googlemaps_pin.png';
  	  var myLatLng = new google.maps.LatLng(52.847153,8.043006);
  		var shadow = new google.maps.MarkerImage('img/googlemaps_schatten.png',
  					new google.maps.Size(52.847153),
  					new google.maps.Point(0.004633),
  					new google.maps.Point(8.043006));

  	  var marker = new google.maps.Marker({
  	      position: myLatLng,
  	      map: map,
  				shadow: shadow,
  				icon: image,
  				title:"Dr. Ambrus - Zahnärzte an der Soeste",
  				zIndex: 15
  	  });

  	  infowindow.open(map,marker);	

  		google.maps.event.addListener(marker, 'click', function() {
  		  infowindow.open(map,marker);
  		});
  	}
	
$('#Einzelbilder').click(function() {
  window.onload()
});
	
	
addOnLoadEvent = function (initialize)
  {
  var mOldOnLoad = window.onload;
  if (typeof window.onload != 'function' ) 
    {
    window.onload = initialize;
    } 
  else 
    {
    window.onload = function () 
      {
      if (mOldOnLoad) mOldOnLoad ();
      initialize ();
      }
    }
  }